Skip to content

feat: add OTel metrics with Prometheus exporter and ServiceMonitor auto-creation - #165

Merged
miyunari merged 2 commits into
mainfrom
feat/operator-metrics
Jul 31, 2026
Merged

miyunari merged 2 commits into
mainfrom
feat/operator-metrics

Conversation

@miyunari

Copy link
Copy Markdown
Member

Summary

  • Add OpenTelemetry SDK metrics with a Prometheus exporter for the operator itself, exposing webhook mutation and controller reconcile counters/histograms on the existing /metrics endpoint
  • Add --enable-service-monitor flag (ENABLE_SERVICE_MONITOR env var) to automatically create a Prometheus ServiceMonitor CR at startup for OpenShift environments
  • Gracefully skip ServiceMonitor creation when the monitoring.coreos.com/v1 API is not available on the cluster
  • Include kustomize component (config/components/service-monitor/) with RBAC and deployment patches for easy opt-in

New metrics

Metric Type Labels Description
webhook.mutations_total Counter namespace, result Webhook mutation request count
webhook.mutation.duration_seconds Histogram namespace, result Webhook mutation handling duration
reconcile.count_total Counter controller, result Controller reconcile operation count
reconcile.duration_seconds Histogram controller, result Controller reconcile operation duration

@miyunari
miyunari force-pushed the feat/operator-metrics branch 2 times, most recently from 1248aa0 to fdfb411 Compare July 26, 2026 15:45
@miyunari
miyunari requested review from SequeI and knrc July 26, 2026 15:47
@miyunari
miyunari force-pushed the feat/operator-metrics branch from f69d6c0 to f97ae5d Compare July 30, 2026 20:19
@miyunari
miyunari enabled auto-merge (squash) July 30, 2026 20:19
miyunari added 2 commits July 30, 2026 22:37
…to-creation

Expose operator-level metrics using the OpenTelemetry SDK with a
Prometheus exporter registered on controller-runtime's metrics registry.
This adds webhook mutation and controller reconcile counters and duration
histograms to the existing /metrics endpoint.

Add --enable-service-monitor flag (ENABLE_SERVICE_MONITOR env var) that
automatically creates a Prometheus ServiceMonitor CR at startup for
OpenShift environments where scraping is the default discovery method.
The operator checks for the monitoring.coreos.com/v1 API at startup and
gracefully skips creation if the CRD is not installed.

Signed-off-by: Nina Bongartz <pninak@web.de>
The service-monitor component adds --enable-service-monitor and
POD_NAMESPACE to the deployment. Including it in the production
overlay by default caused the operator startup to be slower on
clusters without the prometheus-operator CRD, leading to webhook
timeout failures in E2E tests on Kind clusters.

Move the component to opt-in: users who need automatic
ServiceMonitor creation can add the component to their overlay.

Signed-off-by: Nina Bongartz <pninak@web.de>
@miyunari
miyunari force-pushed the feat/operator-metrics branch from f97ae5d to 765a7d1 Compare July 30, 2026 20:39
@miyunari
miyunari merged commit cd7d977 into main Jul 31, 2026
5 checks passed
@miyunari
miyunari deleted the feat/operator-metrics branch July 31, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants